package com.opgea.tutor.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opgea.tutor.TutorException;
import com.opgea.tutor.service.TutorService;
import com.opgea.tutor.web.dto.TutorDTO;

@ManagedBean(name = "tutorSearchController")
@RequestScoped
@Component
@Scope(value = "request")
public class TutorSearchController {

    @Autowired
    private TutorService tutorService;

    private String searchString;
    private List<TutorDTO> tutorList = new ArrayList<TutorDTO>();

    @PostConstruct
    public void init() {
    }

    public String getSearchString() {
	return searchString;
    }

    public void setSearchString(String searchString) {
	this.searchString = searchString;
    }

    public List<TutorDTO> getTutorList() {
	return tutorList;
    }

    public void setTutorList(List<TutorDTO> tutorList) {
	this.tutorList = tutorList;
    }

    public String searchTutors() {
	try {
	    tutorList = tutorService.findAll();
	} catch (TutorException e) {
	    e.printStackTrace();
	}
	return "home.xhtml";
    }

}
